define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格參數配置
            Table.api.init({
                extend: {
                    index_url: 'aps/man/index',
                    add_url: 'aps/man/add',
                    edit_url: 'aps/man/edit',
                    del_url: 'aps/man/del',
                    multi_url: 'aps/man/multi',
                    table: 'aps_man',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                showToggle: false,
                sortName: 'id',
                searchFormVisible: true,
                showToggle: false,
                showColumns: false,
                showExport: false,
                search: false,
                dblClickToEdit: false, //是否啟用雙擊編輯
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), operate:false},
                        {field: 'name', title: __('Name'), operate: 'LIKE %...%', placeholder: '模糊搜索，*表示任意字符'},
                        //{field: 'number', title: __('Number')},
                        {field: 'devicetype1_name', title: __('技能1'), operate:false},
                        //{field: 'ability1', title: __('Ability1')},
                        {field: 'devicetype2_name', title: __('技能2'), operate:false},
                        //{field: 'ability2', title: __('Ability2')},
                        {field: 'devicetype3_name', title: __('技能3'), operate:false},
                        //{field: 'ability3', title: __('Ability3')},
                        {field: 'devicetype4_name', title: __('技能4'), operate:false},
                        //{field: 'ability4', title: __('Ability4')},
                        {field: 'devicetype5_name', title: __('技能5'), operate:false},
                        //{field: 'ability5', title: __('Ability5')},
                        {field: 'devicetype6_name', title: __('技能6'), operate:false},
                        //{field: 'ability6', title: __('Ability6')},
                        {field: 'devicetype7_name', title: __('技能7'), operate:false},
                        //{field: 'ability7', title: __('Ability7')},
                        {field: 'devicetype8_name', title: __('技能8'), operate:false},
                        //{field: 'ability8', title: __('Ability8')},
                        {field: 'devicetype9_name', title: __('技能9'), operate:false},
                        //{field: 'ability9', title: __('Ability9')},
                        {field: 'devicetype10_name', title: __('技能10'), operate:false},
                        //{field: 'ability10', title: __('Ability10')},
                        {field: 'devicetype11_name', title: __('技能11'), operate:false},
                        //{field: 'ability11', title: __('Ability11')},
                        {field: 'devicetype12_name', title: __('技能12'), operate:false},
                        //{field: 'ability12', title: __('Ability12')},
                        {field: 'state', title: __('State'), searchList: {"0":__('State 0'),"1":__('State 1'),"2":__('State 2')}, formatter: Table.api.formatter.normal},
                        //{field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime, operate:false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            //點擊重算能力值
            $(document).on("click", ".csnlz", function () {
                var url = 'aps/man/csnlz';

                var that = this;
                Layer.confirm(__('確定重算能力值?'), {icon: 3, title: '提示'}, function (index) {
                    Backend.api.ajax({
                        url: url,
                    }, function () {
                        Layer.close(index);
                        window.location.reload();
                    });
                });
            });

            // 為表格綁定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});